package com.kuzlak.cms.bean;

import com.kuzlak.cms.constant.ResultConstant;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.SchemaProperty;

@Schema(description  = "返回信息")
public class Result {

    @Schema(description  = "错误号")
    private int code = 501;

    @Schema(description = "错误提示")
    private String msg;

    @Schema(description = "状态")
    private boolean success;
    @Schema(description = "返回数据")
    private Object data;

    public Result() {

    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(int status) {
        this.code = status;
    }

    public Result(boolean success1) {
        if (success1) {
            this.code = ResultConstant.SUCSESS;
        }
        this.success = success1;

    }

    public static Result instance() {
        return new Result();
    }

    public static Result ok() {
        Result result = new Result();
        result.setCode(ResultConstant.SUCSESS);
        return result;
    }

    public static Result ok(Object data) {
        Result result = new Result();
        result.setData(data);
        result.setCode(ResultConstant.SUCSESS);
        return result;
    }

    public static Result failure() {
        Result result = new Result();
        result.setCode(ResultConstant.FAIL);
        return result;
    }

    public static Result failure(Object data) {
        Result result = new Result();
        result.setCode(ResultConstant.FAIL);
        result.setData(data);
        return result;
    }

    public static Result failure(String msg) {
        Result result = new Result();
        result.setMsg(msg);
        result.setCode(ResultConstant.FAIL);
        return result;
    }

    public static Result failure(int code, String msg) {
        Result result = new Result();
        result.setMsg(msg);
        result.setCode(code);
        return result;
    }

    public static Result failure(String msg, Object data) {
        Result result = new Result();
        result.setMsg(msg);
        result.setCode(ResultConstant.FAIL);
        result.setData(data);
        return result;
    }
    public static Result failure(int code, String msg, Object data) {
        Result result = new Result();
        result.setMsg(msg);
        result.setCode(code);
        result.setData(data);
        return result;
    }

    public static Result failure(int code, Object data) {
        Result result = new Result();
        result.setCode(code);
        result.setData(data);
        return result;
    }

    public static Result failure(int status) {
        Result result = new Result();
        result.setCode(status);
        return result;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        if (msg == null) {

            msg = ResultConstant.get(this.code);
        }
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public boolean isSuccess() {
        if (ResultConstant.SUCSESS == code) {
            success = true;
        }
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}

